/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SpravaUzivatelu.java
 *
 * Created on 20.11.2011, 23:34:51
 */
package gui;

import system.Launcher;
import uzivatele.UzivatelRank;

/**
 *
 * @author Johny007
 */
public class SpravaUzivatelu extends javax.swing.JFrame {

    /** Creates new form SpravaUzivatelu */
    public SpravaUzivatelu() {
        initComponents();
        String nazevOkna = "Správa uživatelů";
        this.setTitle("Správce úkolů - " + nazevOkna
                + " - Přihlášen " + Launcher.getInstance().getUzivatel().getEmail()
                + " - " + UzivatelRank.getNameFromRankId(Launcher.getInstance().getUzivatel().getRank()));
        Launcher.getInstance().setOknoDoprostred(this);
        //nullPointerException pokud bude v luncher null
        aplikujRank(Launcher.getInstance().getUzivatel().getRank());
    }

    /**metoda aplikuje rank na dialog a umozni nebo neumozni
     * vytvoreni nebo mazani uzivatele podle prav
     * vykresli jmeno uzivatele a jeho prava do titulku
     * @param ID rank uzivatele
     */
    private void aplikujRank(int rank) {
        String pravaUzivatele = UzivatelRank.getNameFromRankId(rank);
        if (!pravaUzivatele.equals("Administrátor")) {
            TlacitkoVytvoreniUzivatele.setEnabled(false);
            TlacitkoSmazaniUzivatele.setEnabled(false);
        }
        String jmeno = Launcher.getInstance().getUzivatel().getJmeno();
        this.setTitle(jmeno + " (" + pravaUzivatele + ")");

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        SeznamUzivatelu = new javax.swing.JTable();
        LabelSeznamUzivatelu = new javax.swing.JLabel();
        TlacitkoVytvoreniUzivatele = new javax.swing.JButton();
        TlacitkoSmazaniUzivatele = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        SeznamUzivatelu.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Jméno uživatele", "Úkol", "Status úkolu"
            }
        ));
        SeznamUzivatelu.setColumnSelectionAllowed(true);
        SeznamUzivatelu.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(SeznamUzivatelu);
        SeznamUzivatelu.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

        LabelSeznamUzivatelu.setText("Seznam uživatelů");

        TlacitkoVytvoreniUzivatele.setText("Vytvoření uživatele");

        TlacitkoSmazaniUzivatele.setText("Smazat uživatele");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 693, Short.MAX_VALUE)
                    .addComponent(LabelSeznamUzivatelu)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(TlacitkoVytvoreniUzivatele)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(TlacitkoSmazaniUzivatele)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(LabelSeznamUzivatelu)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 345, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TlacitkoVytvoreniUzivatele)
                    .addComponent(TlacitkoSmazaniUzivatele))
                .addGap(57, 57, 57))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */

        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SpravaUzivatelu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SpravaUzivatelu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SpravaUzivatelu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SpravaUzivatelu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new SpravaUzivatelu().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel LabelSeznamUzivatelu;
    private javax.swing.JTable SeznamUzivatelu;
    private javax.swing.JButton TlacitkoSmazaniUzivatele;
    private javax.swing.JButton TlacitkoVytvoreniUzivatele;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
